﻿using System;
using System.Collections.Generic;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using LynxWiki.DomainModel;
using LynxWiki.ViewModels;

namespace LynxWiki.Tests.TopicVersionViewDataTests
{
    [TestClass]
    public class UnitTest1
    {
        [TestMethod]
        public void MinorUpdateToViewDetailTest1()
        {
            TopicVersion tv = new TopicVersion();
            MinorUpdateInstance mui = new MinorUpdateInstance();
            mui.Updater = "jwd";
            mui.UpdatedOn = DateTime.Now;
            mui.UpdateReason = "Test conversion to View Detail";
            tv.MinorUpdates.Add(mui);
            TopicVersionViewData tvd = new TopicVersionViewData(tv);
            tvd.MinorUpdateToViewDetail(tv.MinorUpdates);
            Assert.AreEqual("jwd - " + mui.UpdatedOn + ": Test conversion to View Detail", tvd.MinorUpdateDetails);
        }

        [TestMethod]
        public void MinorUpdateToViewDetailTest2()
        {
            TopicVersion tv = new TopicVersion();
            MinorUpdateInstance mui = new MinorUpdateInstance();
            mui.Updater = "jwd";
            mui.UpdatedOn = DateTime.Now;
            mui.UpdateReason = "Test conversion to View Detail";
            tv.MinorUpdates.Add(mui);
            MinorUpdateInstance mui1 = new MinorUpdateInstance();
            mui1.Updater = "jwd1";
            mui1.UpdatedOn = mui.UpdatedOn;
            mui1.UpdateReason = "Test conversion to View Detail 2";
            tv.MinorUpdates.Add(mui1);
            TopicVersionViewData tvd = new TopicVersionViewData(tv);
            tvd.MinorUpdateToViewDetail(tv.MinorUpdates);
            string tempExpected = "jwd - " + mui.UpdatedOn.ToString() + ": Test conversion to View Detail;" + Environment.NewLine
                + "jwd1 - " + mui.UpdatedOn.ToString() + ": Test conversion to View Detail 2";
            Assert.AreEqual(tempExpected, tvd.MinorUpdateDetails);
        }

        [TestMethod]
        public void CreateListFromMinorUpdateDetailsTest1()
        {
            TopicVersion tv = new TopicVersion();
            MinorUpdateInstance mui = new MinorUpdateInstance();
            mui.Updater = "jwd";
            mui.UpdatedOn = DateTime.Now;
            mui.UpdateReason = "Test conversion to View Detail";
            tv.MinorUpdates.Add(mui);
            TopicVersionViewData tvd = new TopicVersionViewData(tv);
            tvd.MinorUpdateToViewDetail(tv.MinorUpdates);
            Assert.AreEqual("jwd - " + mui.UpdatedOn + ": Test conversion to View Detail", tvd.MinorUpdateDetails);

            List<MinorUpdateInstance> testList = tvd.CreateListFromMinorUpdateDetails();
            Assert.IsInstanceOfType(testList, typeof(List<MinorUpdateInstance>));
            Assert.IsTrue(testList.Count == 1);
            Assert.AreEqual("jwd", testList[0].Updater);
            Assert.AreEqual(mui.UpdatedOn.ToString("yyyy-MM-dd hh:mm:ss"), testList[0].UpdatedOn.ToString("yyyy-MM-dd hh:mm:ss"));
            Assert.AreEqual("Test conversion to View Detail", testList[0].UpdateReason);
        }

        [TestMethod]
        public void CreateListFromMinorUpdateDetailsTest2()
        {
            TopicVersion tv = new TopicVersion();
            MinorUpdateInstance mui = new MinorUpdateInstance();
            mui.Updater = "jwd";
            mui.UpdatedOn = DateTime.Now;
            mui.UpdateReason = "Test conversion to View Detail";
            tv.MinorUpdates.Add(mui);
            MinorUpdateInstance mui1 = new MinorUpdateInstance();
            mui1.Updater = "jwd1";
            mui1.UpdatedOn = mui.UpdatedOn;
            mui1.UpdateReason = "Test conversion to View Detail 2";
            tv.MinorUpdates.Add(mui1);
            TopicVersionViewData tvd = new TopicVersionViewData(tv);
            tvd.MinorUpdateToViewDetail(tv.MinorUpdates);

            List<MinorUpdateInstance> testList = tvd.CreateListFromMinorUpdateDetails();
            Assert.IsInstanceOfType(testList, typeof(List<MinorUpdateInstance>));
            Assert.IsTrue(testList.Count == 2);
            Assert.AreEqual("jwd", testList[0].Updater);
            Assert.AreEqual(mui.UpdatedOn.ToString("yyyy-MM-dd hh:mm:ss"), testList[0].UpdatedOn.ToString("yyyy-MM-dd hh:mm:ss"));
            Assert.AreEqual("Test conversion to View Detail", testList[0].UpdateReason);
            Assert.AreEqual("jwd1", testList[1].Updater);
            Assert.AreEqual("Test conversion to View Detail 2", testList[1].UpdateReason);
        }
    }
}

